home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / shell / xd-2.08 / xd-2 / xd / build < prev    next >
Encoding:
Text File  |  1994-08-30  |  5.4 KB  |  229 lines

  1. #!/usr/local/bin/icmake -qi
  2. /*                              build
  3.  
  4. */
  5.  
  6. string                                      // contain options for
  7.     libxxxa,                    // expanded lib-name
  8.     libs,                                // extra libs, e.g., "-lrss -licce"
  9.     libpath;                       // extra lib-paths, eg, "-L../rss"
  10.  
  11. int
  12.     relink;                                 // internally used: != 0 to relink
  13.  
  14. string
  15.     copt,                // extra C-options
  16.     lopt,                // extra link-options
  17.     wild,                               // wildcard of extension
  18.     current;                            // contains name of current dir.
  19.  
  20. list objfiles(list files)
  21. {
  22.     string
  23.         file,
  24.         objfile;
  25.     int
  26.         i;
  27.  
  28.     for (i = 0; i < sizeof(files); i++)
  29.     {
  30.         file = element(i, files);           // determine element of the list
  31.         objfile = change_ext(file, "o");    // make obj-filename
  32.         if (objfile younger file)           // objfile is younger
  33.         {
  34.             files -= (list)file;            // remove the file from the list
  35.             i--;                            // reduce i to test the next
  36.         }
  37.     }
  38.     return (files);
  39. }
  40.  
  41. list altered(list files, string target)
  42. {
  43.     int
  44.         i;
  45.     string
  46.         file;
  47.  
  48.     for (i = 0; i < sizeof(files); i++)     // try all elements of the list
  49.     {
  50.         file = element(i, files);           // use element i of the list
  51.  
  52.         if (file older target)              // a file is older than the target
  53.         {
  54.             files -= (list)file;            // remove the file from the list
  55.             i--;                            // reduce i to inspect the next
  56.         }                                   // file of the list
  57.     }
  58.     return (files);                         // return the new list
  59. }
  60.  
  61. list file_list(string type, string library)
  62. {
  63.     list
  64.         files;
  65.  
  66.     files = makelist(type);                 // make all files of certain type
  67.     files = altered(files, library);        // keep all files newer than lib.
  68.     files = objfiles(files);                // remove if younger .obj exist
  69.  
  70.     return (files);
  71. }
  72.  
  73. void link(string library, string exe)
  74. {
  75.     if
  76.     (
  77.         relink                           // new library, new main.obj
  78.         ||
  79.         !exists(exe)                     // final program doesn't exist
  80.     )
  81.     {
  82.         printf("\n");
  83.         exec("gcc", "-o", exe, "-l" + library, libs, "-L.", libpath, lopt);
  84.         printf("ok: ", exe, "\n");
  85.     }
  86. }
  87.  
  88. void c_compile(list cfiles)
  89. {
  90.     string
  91.         nextfile;
  92.     int
  93.         i;
  94.  
  95.     if (sizeof(cfiles))            // files to compile ?
  96.     {
  97.             printf("\ncompiling: ", current, "\n\n");
  98.                         // compile all files separately
  99.         for (i = 0; nextfile = element(i, cfiles); i++)
  100.             exec("gcc",
  101.                 "-c -m486 -Wall -funsigned-char " +
  102.                 copt + " " + nextfile);
  103.             relink = 1;
  104.         printf("\n");
  105.     }
  106.     printf("ok: ", current, "\n");
  107. }
  108.  
  109. void updatelib(string library)
  110. {
  111.     list
  112.     arlist,
  113.         objlist;
  114.     string
  115.         to,
  116.         from;
  117.  
  118.     objlist = makelist("*.o");
  119.  
  120.     if (!sizeof(objlist))
  121.         return;
  122.  
  123.     printf("\n");
  124.     relink = 1;
  125.  
  126.     exec("ar", "rvs", library, "*.o");
  127.     exec("rm", "*.o");
  128.  
  129.     printf("\n");
  130. }
  131.  
  132. void std_cpp(string library)
  133. {
  134.     list
  135.         cfiles;
  136.  
  137.     cfiles = file_list(wild, library);      // make list of all cpp-files
  138.  
  139.     c_compile(cfiles);                      // compile cpp-files
  140. }
  141.  
  142. void prefix_class(string class_id)
  143. {
  144.     list
  145.     o_files;
  146.     string
  147.     o_file;
  148.     int
  149.     i;
  150.  
  151.     o_files = makelist("*.o");
  152.  
  153.     for (i = 0; o_file = element(i, o_files); i++)
  154.     exec("mv", o_file, class_id + o_file);
  155. }
  156.  
  157. void cpp_make(string mainfile, string library, string exe, list classes)
  158. {
  159.     int
  160.         index;
  161.  
  162.     wild = "*.cc";
  163.  
  164.                         // make library name
  165.     libxxxa = chdir(".") + "lib" + library + ".a";
  166.  
  167.                                             // first process all classes
  168.     for (index = 0; index < sizeof(classes); index++)
  169.     {
  170.         current = element(index, classes);  // next class to process
  171.         chdir(current);                     // change to directory
  172.  
  173.         current = "subdir " + current;
  174.         std_cpp (libxxxa);                // compile all files
  175.         chdir( "..");                     // go back to parent dir
  176.     }
  177.  
  178.  
  179.     current = "auxiliary *.cc files";
  180.     std_cpp (libxxxa);                    // compile all files in current dir
  181.  
  182.     for (index = 0; index < sizeof(classes); index++)
  183.     {
  184.         current = element(index, classes);  // determine class name
  185.         chdir( current);                  // chdir to a class directory.
  186.     prefix_class((string)index);      // prefix class-number for .o files
  187.         updatelib(libxxxa);
  188.         chdir( "..");                     // go back to parent dir
  189.     }
  190.  
  191.     current = "";                           // no class anymore
  192.  
  193.     updatelib(libxxxa);                // update lib in current dir
  194.  
  195.     if (mainfile != "")                     // mainfile -> do link
  196.     {
  197.         link(library, exe);
  198.         printf
  199.     (
  200.         "\nProgram construction completed.\n"
  201.         "\n"
  202.     );
  203.     }
  204. }
  205.  
  206. void main()
  207. {
  208.     libs    = "-lcclib";        // the libname (no lib, .a)
  209.  
  210.     copt = "-O2";
  211.     lopt = "-s";
  212.     
  213. //    copt = "-DDEBUG";        // Debug-flag set
  214.  
  215. //  remove the echo() statement if you want to see the execed commands
  216. //    echo(OFF);            // do not show commands
  217.  
  218.     cpp_make
  219.     (
  220.         "xd.cc",             // program source
  221.         "xd",                // program library
  222.         "xd",                // exe program
  223.     (list)"Command" +    // classes
  224.     (list)"Match"     +
  225.     (list)"Config"     +
  226.     (list)"Arbiter"
  227.     );
  228. }
  229.